//
//  LoginController.m
//  QQplayground
//
//  Created by zhangxy on 2018/5/21.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "LoginController.h"
#import "BaseTabBarController.h"
#import <UMShare/UMShare.h>
#import "ZCTTMLEmojiLabel.h"
#import "ZTextField.h"
#import "BaseTabBarController.h"
#import "SendCodeController.h"
#import "SVWebViewController.h"
#import "SearchCodeController.h"
#import "FindPwdController.h"

@interface LoginController ()<ZCTTMLEmojiLabelDelegate,UIGestureRecognizerDelegate, UIScrollViewDelegate>{
    CGFloat startY;
    int isPhoneLogin;
    UIButton *checkToLogin;
    UIButton *checkToRegister;
}

@property (nonatomic, strong) UIScrollView *scrollView;
@property(nonatomic,strong) UIView *loginView;
@property(nonatomic,strong) UIView *regView;
@property(nonatomic,strong) UIImageView *imgLine;
@property(nonatomic,strong) UILabel *labTips;
@property(nonatomic,strong) ZTextField *txtName;
@property(nonatomic,strong) ZTextField *txtPwd;
@property(nonatomic,strong) ZTextField *txtPhone;
@property(nonatomic,strong) UIButton *btnTemp;
@property(nonatomic,strong) UIButton *btnTempLogin;



@end

@implementation LoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.hidden = YES;
    self.view.userInteractionEnabled = YES;
    [self createVCView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenKeyboard:)];
    tap.delegate = self;
    [self.view addGestureRecognizer:tap];
    
    
//    _txtName.text = @"gaoyong06@qq.com";
//    _txtPwd.text = @"123456";
//
//    _txtPhone.text = @"18611622736";
    
    
//    UISwipeGestureRecognizer *recognizer;
//    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
//    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
//    [self.view addGestureRecognizer:recognizer];
//
//    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
//    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
//    [self.view addGestureRecognizer:recognizer];
    
}

//- (IBAction)handleSwipeFrom:(UISwipeGestureRecognizer *)sender{
//    if (sender.direction==UISwipeGestureRecognizerDirectionLeft )
//    {
//        [self changeView:checkToRegister];
//    }else if(sender.direction==UISwipeGestureRecognizerDirectionRight)
//    {
//
//        [self changeView:checkToLogin];
//    }
//}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
//    self.navigationController.navigationBar.hidden = NO;
}

-(void)backAction{
    DLog(@"%@",self.view.window.rootViewController);
    if(![self.view.window.rootViewController isKindOfClass:[BaseTabBarController class]]){
        
        self.view.window.rootViewController = [[BaseTabBarController alloc] init];
    }else{
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

// 隐藏键盘
-(void)hiddenKeyboard:(id)sender
{
    [_txtPwd resignFirstResponder];
    [_txtName resignFirstResponder];
    [_txtPhone resignFirstResponder];
}

-(void)changeView:(UIButton *)sender{
    [self hiddenKeyboard:nil];
    
    CGFloat offset = sender.tag * _scrollView.width;
    [_scrollView setContentOffset:CGPointMake(offset, 0) animated:YES];
    
    [UIView animateWithDuration:0.25 animations:^{
        CGPoint ic = _imgLine.center;
        ic.x = sender.center.x;
        _imgLine.center = ic;
    }];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger offset = scrollView.contentOffset.x/ScreenWidth;
    if (offset == 0) {
        [self changeView:checkToLogin];
    }else{
        [self changeView:checkToRegister];
    }
}


-(void)doThirdLogin:(UIButton *) sender{
    if(sender.tag == 10){
        DLog(@"普通登录");
        [NetworkUtil POST:API_Login parameters:@{@"account":_txtName.text,@"password":_txtPwd.text,@"phone_area_code":convertToString(_btnTempLogin.titleLabel.text)} success:^(id responseObject,NSDictionary *dictionary) {
            NSLog(@"%@",dictionary);
            [self doLoginResult:dictionary];
        } failure:^(NSError *error,NSString *message) {
            //判断输入的手机号，邮箱和密码是否为空时返回的文案
            if ([self.txtName.text isEqualToString:@""]){
                message = @"请输入手机号或邮箱";
            } else if ([self.txtPwd.text isEqualToString:@""]){
                message = @"密码别忘了填写";
            }
            //判断输入的手机号，邮箱和密码出错时返回的文案
            else if (isPhoneLogin){
                message = @"手机号和密码都正确才能打开乐园的门";
            } else {
                message = @"邮箱和密码都正确才能打开乐园的门";
            }
            NSLog(@"message............%@",message);
            [PopUtil showMessage:message];
        }];
        
    }
    if(sender.tag == 11){
        DLog(@"获取验证码");
        if(convertToString(_txtPhone.text).length > 0 && convertToString(_txtPhone.text).length < 8 ){
            [PopUtil showMessage:@"手机号码输入错啦"];
//            [self.view makeToast:@"手机号码输入错啦"];
            return;
        } else if (convertToString(_txtPhone.text).length == 0){
            [PopUtil showMessage:@"请输入手机号码"];
//            [self.view makeToast:@"请输入手机号码"];
            return;
        }
        
        [self imgCodeShow];
        
    }
    if(sender.tag == 1){
        NSLog(@"微信登录");
        [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
            
            NSLog(@"%@",result);
            if(!error){
                UMSocialUserInfoResponse *response = result;
                
                [self checkUserRegister:response];
                
            }
        }];
        
    }
    if(sender.tag == 2){
        NSLog(@"新浪微博登录");
        
        [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_Sina currentViewController:self completion:^(id result, NSError *error) {
            NSLog(@"%@",result);
            if(!error){
                UMSocialUserInfoResponse *response = result;
                
                [self checkUserRegister:response];
            }
        }];
    }
    if(sender.tag == 3){
        NSLog(@"QQ登录");
        [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:self completion:^(id result, NSError *error) {
            NSLog(@"%@",result);
            if(!error){
                UMSocialUserInfoResponse *response = result;
                
                [self checkUserRegister:response];
            }
        }];
    }
}

-(void)searchCode:(UIButton *)sender{
    SearchCodeController *vc = [[SearchCodeController alloc] init];
    [vc setZZPageResultBlock:^(id obj) {
        if([sender isEqual:_btnTemp]){
            [_btnTemp setTitle:convertToString(obj) forState:0];
        }else{
            [_btnTempLogin setTitle:convertToString(obj) forState:0];
            
        }
    }];
    [self openPushVC:vc];
}

- (void)imgCodeShow
{
    //发送网络请求，想服务器端验证图形验证码的正确性
    NSDictionary *params = [[NSDictionary alloc] initWithObjects:@[_txtPhone.text,convertToString(_btnTemp.titleLabel.text)] forKeys:@[@"phone",@"phone_area_code"]];
    DLog(@"params：%@",params);
    [NetworkUtil POST:API_SendSms parameters:params success:^(id responseObject, NSDictionary *dict) {
        [PopUtil showMessage:@"验证码已发送" positionType:PopPositionTypeMiddle];
        SendCodeController *vc = [[SendCodeController alloc] init];
        vc.phone_area_code = convertToString(_btnTemp.titleLabel.text);
        vc.phone = convertToString(_txtPhone.text);
        [self openPushVC:vc];
    } failure:^(NSError *error, NSString *message) {
        NSLog(@"message->>>>>>>>>%@", message);
        if(convertToString(message).length>0){
            [PopUtil showMessage:message positionType:PopPositionTypeMiddle];
        }
    }];
}

-(void)checkUserRegister:(UMSocialUserInfoResponse *)response{
//    NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity:0];
//    [userInfo setObject:convertToString(response.uid) forKey:@"userId"];
//    [userInfo setObject:convertToString(@"") forKey:@"phone"];
//    [userInfo setObject:convertToString(response.name) forKey:@"userName"];
//    [userInfo setObject:@"123456" forKey:@"passWord"];
//    [userInfo setObject:convertToString(response.iconurl) forKey:@"imageUrl"];
//    if(response.platformType == UMSocialPlatformType_WechatSession){
//        [userInfo setObject:convertToString(response.openid) forKey:@"openid"];
//    }else{
//        [userInfo setObject:convertToString(response.uid) forKey:@"openid"];
//    }
//    
//    [userInfo setObject:convertToString(@"0") forKey:@"isYj"];
//    [userInfo setObject:convertToString(@"0") forKey:@"isDoctor"];
    
    [NetworkUtil POST:API_LoginQQ parameters:@{@"open_id":convertToString(response.openid),@"access_token":convertToString(response.accessToken)} success:^(id responseObject, NSDictionary *dict) {
        [self doLoginResult:dict];
        [PopUtil showMessage:@"QQ登录成功！"];
    } failure:^(NSError *error, NSString *message) {
        [PopUtil showMessage:message];
    }];
}


-(void)doLoginResult:(NSDictionary *) dictionary{
    NSLog(@"%@",dictionary);
    User *msg = [[User alloc] initWithDictionary:dictionary[@"data"][@"user_info"]];
    msg.isOnline = YES;
    [UserUtil saveUser:msg];
    User *user  =  [UserUtil getUser];
    if (user.isOnline) {
        self.view.window.rootViewController = [[BaseTabBarController alloc] init];
    }
}

-(void)changeLoginType:(UIButton *) btn{
    if(isPhoneLogin){
        
        [btn setTitle:@"手机号登录" forState:0];
        [_txtName setPlaceholder:@"请输入你的邮箱"];
        
        [_txtName setFrame:CGRectMake(20, 8.5, ScreenWidth - 40, 35)];
        
        _btnTempLogin.hidden = YES;
       
    }else{
        [_txtName setFrame:CGRectMake(50, 8.5, ScreenWidth - 40 - 60, 35)];
        
        
        _btnTempLogin.hidden = NO;
        
        [btn setTitle:@"邮箱登录" forState:0];
        [_txtName setPlaceholder:@"请输入你的手机号码"];
        
    }
    
    
    isPhoneLogin = !isPhoneLogin;
}

-(void)findPwd:(UIButton *) btn{
    FindPwdController *vc = [[FindPwdController alloc] init];
    [self openPushVC:vc];
}


-(void)createVCView{
    UIImage *backImage =[UIImage imageNamed:@"base_bg.jpg"];
    self.view.layer.contents=(id)backImage.CGImage;
    self.view.layer.backgroundColor = UIColorFromRGB(0x67ACA6).CGColor;
    
    UIButton *backBtn = [self createButton:@"login_close"];
    [backBtn setFrame:CGRectMake(10, StatusBarHeight, 44, 44)];
    [backBtn setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    [backBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
    [backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    [self createTopView];
    [self.view addSubview:self.scrollView];
}

- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, startY, ScreenWidth, ScreenHeight-startY)];
        _scrollView.backgroundColor = [UIColor clearColor];
        _scrollView.contentSize = CGSizeMake(_scrollView.width*2, 0);
        _scrollView.pagingEnabled = YES;
        _scrollView.bounces = NO;
        _scrollView.delegate = self;
        _scrollView.showsHorizontalScrollIndicator = NO;
        [_scrollView addSubview:self.loginView];
        [_scrollView addSubview:self.regView];
    }
    return _scrollView;
}

- (UIView *)loginView
{
    if (!_loginView) {
        _loginView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _scrollView.width, _scrollView.height)];
        _loginView.backgroundColor = UIColor.clearColor;
        [self createLoginView];
    }
    return _loginView;
}

- (UIView *)regView
{
    if (!_regView) {
        _regView   = [[UIView alloc] initWithFrame:CGRectMake(_loginView.width, 0, _scrollView.width, _scrollView.height)];
        _regView.backgroundColor = UIColor.clearColor;
        [self createRegisterView];
    }
    return _regView;
}

-(void)createTopView{
    CGFloat th =0.16*ScreenHeight;
    CGFloat top_y = 0.12*ScreenHeight;
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, top_y, ScreenWidth, th)];
    UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth/2 - 100, 0, 200, 30)];
    [iconView setImage:[UIImage imageNamed:@"qzone"]];
    [iconView setContentMode:UIViewContentModeScaleAspectFit];
    [iconView setBackgroundColor:UIColor.clearColor];
    
//    _labTips = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, ScreenWidth, 30)];
//    [_labTips setFont:FontSeventeen];
//    [_labTips setText:@"注册到世界的边缘的宇宙里"];
//    [_labTips setTextAlignment:NSTextAlignmentCenter];
//    [_labTips setTextColor:UIColorFromRGB(TextWhiteColor)];
    
    checkToLogin = [self createButton:@""];
    [checkToLogin setTitle:@"登录" forState:0];
    [checkToLogin setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [checkToLogin addTarget:self action:@selector(changeView:) forControlEvents:UIControlEventTouchUpInside];
    [checkToLogin setFrame:CGRectMake(0.33*ScreenWidth, th - 35, 40, 30)];
    [checkToLogin.titleLabel setFont:FontSeventeen];
    checkToLogin.tag = 0;
    
    checkToRegister = [self createButton:@""];
    [checkToRegister setTitle:@"注册" forState:0];
    [checkToRegister.titleLabel setFont:FontSeventeen];
    [checkToRegister setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [checkToRegister addTarget:self action:@selector(changeView:) forControlEvents:UIControlEventTouchUpInside];
    [checkToRegister setFrame:CGRectMake(0.58*ScreenWidth, th - 35, 40, 30)];
    checkToRegister.tag = 1;
    
    _imgLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, th - 5, 20, 2)];
    [_imgLine setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
    CGPoint ic = _imgLine.center;
    ic.x = checkToLogin.center.x;
    _imgLine.center = ic;
    
    
    [topView addSubview:iconView];
    [topView addSubview:_labTips];
    [topView addSubview:checkToLogin];
    [topView addSubview:checkToRegister];
    [topView addSubview:_imgLine];
    
    
    [self.view addSubview:topView];
    startY = CGRectGetMaxY(topView.frame) + 28;
}

-(void)createLoginView{
    CGFloat y = 0;
    
    UIView *itemBgView = [[UIView alloc] initWithFrame:CGRectMake(20, y, ScreenWidth-40, 52)];
    itemBgView.layer.cornerRadius = 11.0f;
    itemBgView.layer.masksToBounds  = YES;
    [itemBgView setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
    [_loginView addSubview:itemBgView];
    
    _txtName = [self createTextField:@"请输入你的手机号码" y:y];
    [_txtName setFrame:CGRectMake(50, 8.5, ScreenWidth - 40 - 60, 35)];
    [_txtName setKeyboardType:UIKeyboardTypeDefault];
    [_loginView addSubview:_txtName];
    
    
    _btnTempLogin = [[UIButton alloc] initWithFrame:CGRectMake(20, 8.5, 55, 35)];
    [_btnTempLogin.titleLabel setFont:FontSeventeen];
    [_btnTempLogin setTitleColor:UIColorFromRGB(BgTitleColor) forState:0];
    [_btnTempLogin setTitle:@"+86" forState:0];
    [_btnTempLogin addTarget:self action:@selector(searchCode:) forControlEvents:UIControlEventTouchUpInside];
    [_loginView addSubview:_btnTempLogin];
    
    
    
//    _txtName = [self createTextField:@"你的手机号码/邮箱" y:y];
//    [_loginView addSubview:_txtName];
    
    y = y + 15 + 52;
    
    _txtPwd = [self createTextField:@"请输入密码" y:y];
    _txtPwd.secureTextEntry = true;
    
    
    [_loginView addSubview:_txtPwd];
    
    y = y + 15 + 52;
    
    
    UIButton *btnFindPwd = [[UIButton alloc] initWithFrame:CGRectMake(20, y, 65, 30)];
    [btnFindPwd.titleLabel setFont:FontFiftent];
    [btnFindPwd setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [btnFindPwd setTitle:@"忘记密码" forState:0];
    [btnFindPwd addTarget:self action:@selector(findPwd:) forControlEvents:UIControlEventTouchUpInside];
    [_loginView addSubview:btnFindPwd];
    
    
    UIButton *btnEmailLogin = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 95, y, 75, 30)];
    [btnEmailLogin.titleLabel setFont:FontFiftent];
    [btnEmailLogin setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [btnEmailLogin setTitle:@"邮箱登录" forState:0];

    [btnEmailLogin addTarget:self action:@selector(changeLoginType:) forControlEvents:UIControlEventTouchUpInside];
    [_loginView addSubview:btnEmailLogin];
    isPhoneLogin = YES;
    
    y = y + 30 + 30;
    
    
    UIButton *loginBtn = [self createButton:@""];
    [loginBtn setFrame:CGRectMake(ScreenWidth/2 - 110/2, y, 110, 52)];
    [loginBtn setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
    loginBtn.layer.cornerRadius = 26.0f;
    loginBtn.layer.masksToBounds = YES;
    [loginBtn setTitle:@"登录" forState:0];
    [loginBtn setTitleColor:UIColorFromRGB(BgTitleColor) forState:0];
    [loginBtn.titleLabel setFont:FontSeventeen];
    loginBtn.tag = 10;
    [loginBtn addTarget:self action:@selector(doThirdLogin:) forControlEvents:UIControlEventTouchUpInside];
    [_loginView addSubview:loginBtn];
    
    y = y + 30 + 52;
    
    UILabel *tlab = [[UILabel alloc] initWithFrame:CGRectMake(0, y, ScreenWidth, 21)];
    [tlab setText:@"其它登录方式"];
    [tlab setTextAlignment:NSTextAlignmentCenter];
    [tlab setTextColor:UIColorFromRGB(TextWhiteColor)];
    [tlab setFont:ListTimeFont];
    [_loginView addSubview:tlab];
    
    y = y + 41;
    
    [self createLoginItems:y];
}

-(void)createRegisterView{
    
    CGFloat y = 0;
    UIView *itemBgView = [[UIView alloc] initWithFrame:CGRectMake(20, y, ScreenWidth-40, 55)];
    itemBgView.layer.cornerRadius = 11.0f;
    itemBgView.layer.masksToBounds  = YES;
    [itemBgView setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
    [_regView addSubview:itemBgView];

    _txtPhone = [self createTextField:@"输入手机号码" y:y];
    [_txtPhone setFrame:CGRectMake(50, 10, ScreenWidth - 40 - 60, 35)];
    [_txtPhone setKeyboardType:UIKeyboardTypePhonePad];
    [itemBgView addSubview:_txtPhone];
    
    
    _btnTemp = [[UIButton alloc] initWithFrame:CGRectMake(15, 10, 55, 35)];
    [_btnTemp.titleLabel setFont:FontSeventeen];
    [_btnTemp setTitleColor:UIColorFromRGB(BgTitleColor) forState:0];
    [_btnTemp setTitle:@"+86" forState:0];
    [_btnTemp addTarget:self action:@selector(searchCode:) forControlEvents:UIControlEventTouchUpInside];
    [itemBgView addSubview:_btnTemp];
    
    y = y + 55 + 35;
    
    
    UIButton *loginBtn = [self createButton:@""];
    [loginBtn setFrame:CGRectMake(ScreenWidth/2 - 121/2, y, 121, 52)];
    [loginBtn setBackgroundColor:UIColor.whiteColor];
    loginBtn.layer.cornerRadius = 26.0f;
    loginBtn.layer.masksToBounds = YES;
    [loginBtn setTitle:@"获取验证码" forState:0];
    [loginBtn setTitleColor:UIColorFromRGB(BgTitleColor) forState:0];
    [loginBtn.titleLabel setFont:FontSeventeen];
    loginBtn.tag = 11;
    [loginBtn addTarget:self action:@selector(doThirdLogin:) forControlEvents:UIControlEventTouchUpInside];
    [_regView addSubview:loginBtn];
    
    y = y + 52 + 15;
    
    ZCTTMLEmojiLabel *label = [self createLinkLabel:y];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setFont:FontThirteen];
    [_regView addSubview:label];
    [self addLinkMessage:label text:@"注册即代表同意 <a href=\"statement\">《隐私权声明》</a>"];
}



-(void)createLoginItems:(CGFloat) ty{
    CGFloat x = 40;
    CGFloat space = 65;
    CGFloat w = (ScreenWidth - 80 - 65*2)/3;
    
    UIButton *btn = [self createButton:@"login_qq"];
    btn.tag = 3;
    [btn setFrame:CGRectMake(ScreenWidth/2 - w/2, ty, w, w)];
    [btn addTarget:self action:@selector(doThirdLogin:) forControlEvents:UIControlEventTouchUpInside];
    [_loginView addSubview:btn];
    
//    NSArray *icons = @[@"login_wechat",@"login_sina",@"login_qq"];
    
//    for(int i=0;i<icons.count;i++){
//        UIButton *btn = [self createButton:icons[i]];
//        btn.tag = i+1;
//        [btn setFrame:CGRectMake(x+i*w+i*space, ty, w, w)];
//        [btn addTarget:self action:@selector(doThirdLogin:) forControlEvents:UIControlEventTouchUpInside];
//        [_loginView addSubview:btn];
//
//    }
}





-(UIButton *) createButton:(NSString *) imageName{
    UIButton *btn = ({
        UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [backBtn setImage:[UIImage imageNamed:convertToString(imageName)] forState:0];
        backBtn;
    });
    return btn;
}

-(ZTextField *) createTextField:(NSString *) placeHolder y:(CGFloat )ty{
    ZTextField *btn = ({
        ZTextField *backBtn = [ZZViewUtils createZTextField:placeHolder padding:20];
        [backBtn setFrame:CGRectMake(20, ty, ScreenWidth-40, 52)];
        backBtn;
    });
    return btn;
}

#pragma mark - gesture delegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"ZCTTMLEmojiLabel"]) {
        return NO;
    }
    return YES;
    
}

-(ZCTTMLEmojiLabel *)createLinkLabel:(CGFloat) y{
    ZCTTMLEmojiLabel *label = [[ZCTTMLEmojiLabel alloc] initWithFrame:CGRectMake(20, y, ScreenWidth - 40, 30)];
    [label setTextAlignment:NSTextAlignmentLeft];
    [label setFont:ListTimeFont];
    [label setTextColor:UIColorFromRGB(TextWhiteColor)];
    [label setLinkColor:UIColorFromRGB(TextLinkColor)];
    [label setDelegate:self];
    label.userInteractionEnabled = YES;
    
    return label;
}

-(void)addLinkMessage:(ZCTTMLEmojiLabel *) label text:(NSString *)text{
    text = [ZZCoreTools replaceMessageEmoji:text];
    NSString *sugguestText = text;
    NSMutableDictionary *sugguestDict = [label getTextADict:sugguestText];
    if(sugguestDict){
        label.text = sugguestDict[@"text"];
        NSArray *sugguestArr = sugguestDict[@"arr"];
        //    [_emojiLabel setText:tempText];
        for (NSDictionary *item in sugguestArr) {
            NSString *text = item[@"htmlText"];
            int loc = [item[@"realFromIndex"] intValue];
            // 一定要在设置text文本之后设置
            [label addLinkToURL:[NSURL URLWithString:item[@"url"]] withRange:NSMakeRange(loc, text.length)];
        }
    }
}

// 链接点击
-(void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url{
    DLog(@"链接地址:%@",url.absoluteString);
    
    if([@"pwd" isEqual:url.absoluteString]){
        // 找回密码
    }
    if([@"statement" isEqual:url.absoluteString]){
        SVWebViewController *vc = [[SVWebViewController alloc] initWithURL:[NSURL URLWithString:@"http://hd.qzone.cc/h5/privacy"]];
        self.navigationController.navigationBar.hidden = NO;
        [self openPushVC:vc];
    }
    
}

// 链接点击
-(void)ZCMLEmojiLabel:(ZCTTMLEmojiLabel *)emojiLabel didSelectLink:(NSString *)link withType:(ZCTTMLEmojiLabelLinkType)type{
    DLog(@"意外添加的：%@",link);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
